package com.txw.javaCore.server.service;

import com.google.gson.Gson;
import com.txw.javaCore.model.entity.SysLog;
import com.txw.javaCore.model.request.UserLoginRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @PROJECT_NAME: JavaCoreB2
 * @DESCRIPTION:
 * @Author: 涂玄武
 * @DATE: 2021/2/22 17:30
 */
@Service
@Slf4j
@EnableAsync
public class SysLogService {

    /**
     * 记录用户登录成功的信息入数据库
     * @param request
     */
    @Async
    public void recordLog(UserLoginRequest request){
        try {
            SysLog entity = new SysLog();
            entity.setUserId(request.getUserId());
            entity.setModule("用户登录模块");
            entity.setData(new Gson().toJson(request));
            entity.setMemo("用户登录成功记录相关登录信息");
            entity.setCreateTime(new Date());

            //插入数据库

        } catch (Exception e){
            log.error("系统日志记录-记录用户登录成功的信息入数据库-发生异常：{}",request,e.fillInStackTrace());
        }
    }
}
